***** Rasmussen, Anne, Stefanie Reher and Dimiter Toshkov. 
	* "The Opinion-Policy Nexus in Europe and the Role of Political Institutions".
	* European Journal of Political Research.

*** Replication code

*** 18/04/2018

******************************************************************************************************
******************************************************************************************************

global folder "[INSERT PATH]"

use $folder\RRT_EJPR_2018.dta, clear


* grand-mean centering 
foreach v in p1 logsalience year2 om logsalience mip_v1 enpp1 inflexec {
sum `v' 
cap gen `v'_c = `v' - r(mean)
}


*** Table 1: Effects on the relationship between public opinion and policy
* Model 1
meologit policy3n1 p1_c || issue: p1_c, cov(uns)
* Model 2
meologit policy3n1 p1_c || country: p1_c, cov(uns)
* Model 3
meologit policy3n1 c.p1_c##c.enpp1_c c.p1_c##i.parl_cheib c.p1_c##i.bicam c.p1_c##i.fed c.p1_c##i.EU c.p1_c##c.logsalience_c c.p1_c##c.year2_c || issue: p1_c, cov(uns)
* Model 4
meologit policy3n1 c.p1_c##c.enpp1_c c.p1_c##c.inflexec_c c.p1_c##i.bicam c.p1_c##i.fed c.p1_c##i.EU c.p1_c##c.logsalience_c c.p1_c##c.year2_c || issue: p1_c, cov(uns)


*** Table 2: Congruence by country and policy issue
tabstat con1, by(country) stats(mean, N)
tabstat con1, by(issue) stats(mean, N)


*** Table 3: Effects on public opinion-policy congruence
* Model 5
melogit con1 || issue: 
* Model 6
melogit con1 || country: 
* Model 7
melogit con1 om_c enpp1_c i.parl_cheib i.bicam i.fed i.EU logsalience_c year2_c || issue: 
* Model 8
melogit con1 om_c enpp1_c inflexec_c i.bicam i.fed i.EU logsalience_c year2_c || issue: 


*** Predicted probabilities of congruence in unicameral and bicameral systems, based on average marginal effects (Model 8)
margins, at(bicam=(0 1)) predict(fixedonly)


*** Figure 1: Predicted coefficients of public opinion for each issue 
meologit policy3n1 p1_c || issue: p1_c, cov(uns)
cap drop u0* u1*
predict u0 u1, reffects reses(u0se u1se)
gen u0new=u0 + 4.907399 
gsort +u0new -issuetag 
gen u0rank=sum(issuetag)
capture drop labpos
gen labpos = u0new + 1.96*u0se + 3 
replace labpos = u0new - 1.96*u0se - 3 if (floor(u0rank/2))*2==u0rank 
serrbar u0new u0se u0rank if issuetag==1, scale(1.96) yline(4.907399 , lpattern(dash) lcolor(black)) scheme(s2mono) graphregion(color(white)) addplot(scatter labpos u0rank, mlabel(issue) msymbol(none) mlabpos(0) mlabsize(tiny))  name(g2, replace)
graph save Graph $folder\Figure1.gph, replace
graph export $folder\map.Figure1, replace width(5000)

*** Figure 2: Predicted coefficients of public opinion for each country
meologit policy3n1 p1_c || country: p1_c, cov(uns)
cap drop u0* u1*
predict u0c u1c, reffects reses(u0sec u1sec)
gen u0newc=u0c + 2.620068
gsort +u0newc -countrytag 
gen u0rankc=sum(countrytag)
capture drop labpos
gen labpos = u0newc + 1.96*u0sec + 0.02 
replace labpos = u0newc - 1.96*u0sec - 0.02 if (floor(u0rankc/2))*2==u0rankc 
serrbar u0newc u0sec u0rankc if countrytag==1, scale(1.96) yline(2.620068) scheme(s2mono) graphregion(color(white)) addplot(scatter labpos u0rankc, mlabel(country) msymbol(none) mlabpos(0) mlabsize(tiny)) name(g1, replace)
graph save Graph $folder\Figure2.gph, replace
graph export $folder\map.Figure2, replace width(5000)

*** FIGURE 3 
ssc install spmap
ssc install shp2dta
ssc install mif2dta

* download "countries" files from http://www.naturalearthdata.com/downloads/10m-cultural-vectors/ and save in "folder"
shp2dta using $folder\ne_10m_admin_0_countries.shp, database(world) coordinates(coord) genid(id)

* move files "europe.dta" and "coord.dta" from "Documents" folder to "folder" 
use $folder\world.dta, clear
list id NAME

* (1) drop countries that are not in our dataset and (2) create an id variable that matches the country variable in the dataset
recode id 17=1 20=2 24=3 100=4 60=5 61=6 65=7 73=8 75=9 78=10 62=11 91=12 102=13 111=14 108=15 113=16 139=17 ///
137=18 138=19 151=20 170=21 183=22 186=23 191=24 214=25 215=26 72=27 216=28 41=29 169=30 82=32 else=., gen(country)
drop if country==.
save $folder\europe.dta, replace

* generate and attach data: mean congruence by country
use $folder\RRT_EJPR_2018.dta, clear
gen congruence=.
forval c=1/32 {
sum con1 if country==`c'
replace congruence=r(mean) if country==`c'
}
keep country congruence
duplicates drop
save $folder\congruence.dta, replace

use $folder\europe.dta, clear
merge 1:1 country using $folder\congruence.dta

* generate map
spmap congruence using $folder\coord.dta, id(id) fcolor(Greys2) clmethod(c) clbreaks(.4(.1)1)
graph save Graph $folder\Figure3.gph, replace
graph export $folder\map.Figure3, replace width(10000)



********** Models referred to in the text and in endnotes

*** Endnote ix: models with regime type excluding Switzerland 
* Model 3
meologit policy3n1 c.p1_c##c.enpp1_c c.p1_c##i.parl_cheib c.p1_c##i.bicam c.p1_c##i.fed c.p1_c##i.EU c.p1_c##c.logsalience_c c.p1_c##c.year2_c if country!=29 || issue: p1_c, cov(uns)
* Model 7
melogit con1 om_c enpp1_c i.parl_cheib i.bicam i.fed i.EU logsalience_c year2_c if country!=29 || issue: 


*** Endnote x: analysis substituting ranking of salience for level of salience (results not shown)
pwcorr logsalience saliencerank, obs sig
* Model 3
meologit policy3n1 c.p1_c##c.enpp1_c c.p1_c##i.parl_cheib c.p1_c##i.bicam c.p1_c##i.fed c.p1_c##i.EU c.p1_c##c.saliencerank c.p1_c##c.year2_c || issue: p1_c, cov(uns)
* Model 4
meologit policy3n1 c.p1_c##c.enpp1_c c.p1_c##c.inflexec_c c.p1_c##i.bicam c.p1_c##i.fed c.p1_c##i.EU c.p1_c##c.saliencerank c.p1_c##c.year2_c || issue: p1_c, cov(uns)
* Model 7
melogit con1 om_c enpp1_c i.parl_cheib i.bicam i.fed i.EU saliencerank year2_c || issue: 
* Model 8
melogit con1 om_c enpp1_c inflexec_c i.bicam i.fed i.EU saliencerank year2_c || issue: 


*** Endnote xi: Brant Tests of parallel regression line assumption for ordered logit regression equivalent to Models 1 & 2 
ologit policy3n1 p1_c
brant


*** Endnote xv: Models 1-4 with binary measure of policy
* Model 1
melogit policy p1_c || issue: p1_c, cov(uns)
* Model 2
melogit policy p1_c || country: p1_c, cov(uns)
* Model 3
melogit policy c.p1_c##c.enpp1_c c.p1_c##i.parl_cheib c.p1_c##i.bicam c.p1_c##i.fed c.p1_c##i.EU c.p1_c##c.logsalience_c c.p1_c##c.year2_c || issue: p1_c, cov(uns)
* Model 4
melogit policy c.p1_c##c.enpp1_c c.p1_c##c.inflexec_c c.p1_c##i.bicam c.p1_c##i.fed c.p1_c##i.EU c.p1_c##c.logsalience_c c.p1_c##c.year2_c || issue: p1_c, cov(uns)


*** Testing one institutional variable at a time
* Opinion-policy link 
meologit policy3n1 c.p1_c##c.enpp1_c || issue: p1_c, cov(uns)
meologit policy3n1 c.p1_c##i.parl_cheib || issue: p1_c, cov(uns)
meologit policy3n1 c.p1_c##c.inflexec_c || issue: p1_c, cov(uns)
meologit policy3n1 c.p1_c##i.bicam || issue: p1_c, cov(uns)
meologit policy3n1 c.p1_c##i.fed || issue: p1_c, cov(uns)
meologit policy3n1 c.p1_c##i.EU || issue: p1_c, cov(uns)
meologit policy3n1 c.p1_c##c.logsalience_c || issue: p1_c, cov(uns)
meologit policy3n1 c.p1_c##c.year2_c || issue: p1_c, cov(uns) 
meologit policy3n1 c.p1_c##i.plur || issue: p1_c, cov(uns)
meologit policy3n1 c.p1_c##c.gallyear  || issue: p1_c, cov(uns)
meologit policy3n1 c.p1_c##c.distmagyear || issue: p1_c, cov(uns)
meologit policy3n1 c.p1_c##c.mip_v1_c || issue: p1_c, cov(uns)
* Congruence
melogit con1 om_c enpp1_c  || issue: 
melogit con1 om_c i.parl_cheib || issue: 
melogit con1 om_c inflexec_c || issue:
melogit con1 om_c i.bicam || issue:
melogit con1 om_c i.fed || issue: 
melogit con1 om_c EU || issue: 
melogit con1 om_c logsalience_c || issue: 
melogit con1 om_c year2_c || issue: 
melogit con1 om_c plur || issue: 
melogit con1 om_c gallyear || issue: 
melogit con1 om_c distmagyear || issue: 
melogit con1 om_c mip_v1_c || issue: 

 

******************************************************************************************************
******************************************************************************************************
******************************** ONLINE APPENDIX *****************************************************

*** Table C1
sum p1
sum policy3n1
sum con1


*** Table C2
tabstat issue, by(country) stats(N)
tabstat p1 policy3n1 con1, by(country) stats(mean, sem)


*** Table C3
tabstat country, by(issue) stats(N)
tabstat p1 policy3n1 con1, by(issue) stats(mean, sem)


*** Table D1
tabstat enpp1 parl_cheib inflexec bicam fed, by(country)


*** Table E1
* PR/majoritarian system dummy 
meologit policy3n1 c.p1_c##i.plur c.p1_c##i.parl_cheib c.p1_c##i.bicam c.p1_c##i.fed c.p1_c##i.EU c.p1_c##c.logsalience_c c.p1_c##c.year2_c || issue: p1_c, cov(uns)
* Gallagher Index 
meologit policy3n1 c.p1_c##c.gallyear c.p1_c##i.parl_cheib c.p1_c##i.bicam c.p1_c##i.fed c.p1_c##i.EU c.p1_c##c.logsalience_c c.p1_c##c.year2_c || issue: p1_c, cov(uns)
* Average district magnitude 
meologit policy3n1 c.p1_c##c.distmagyear c.p1_c##i.parl_cheib c.p1_c##i.bicam c.p1_c##i.fed c.p1_c##i.EU c.p1_c##c.logsalience_c c.p1_c##c.year2_c || issue: p1_c, cov(uns)
	

*** Table E2
* PR/majoritarian system dummy 
melogit con1 om_c plur i.parl_cheib i.bicam i.fed i.EU logsalience_c year2_c || issue: 
* Gallagher Index 
melogit con1 om_c gallyear i.parl_cheib i.bicam i.fed i.EU logsalience_c year2_c || issue: 
* Average district magnitude 
melogit con1 om_c distmagyear i.parl_cheib i.bicam i.fed i.EU logsalience_c year2_c || issue: 


*** Table F2
* Model 1
meologit policy3n1 c.p1_c##c.enpp1_c c.p1_c##i.parl_cheib c.p1_c##i.bicam c.p1_c##i.fed c.p1_c##c.logsalience_c c.p1_c##c.year2_c if mip_v1_c!=. || issue: p1_c, cov(uns)
* Model 2
meologit policy3n1 c.p1_c##c.enpp1_c c.p1_c##i.parl_cheib c.p1_c##i.bicam c.p1_c##i.fed c.p1_c##c.mip_v1_c c.p1_c##c.year2_c if mip_v1_c!=. || issue: p1_c, cov(uns)
* Model 3
meologit policy3n1 c.p1_c##c.enpp1_c c.p1_c##c.inflexec c.p1_c##i.bicam c.p1_c##i.fed c.p1_c##c.logsalience_c c.p1_c##c.year2_c if mip_v1_c!=. || issue: p1_c, cov(uns)
* Model 4
meologit policy3n1 c.p1_c##c.enpp1_c c.p1_c##c.inflexec c.p1_c##i.bicam c.p1_c##i.fed c.p1_c##c.mip_v1_c c.p1_c##c.year2_c if mip_v1_c!=. || issue: p1_c, cov(uns)


*** Table F3
* Model 5
melogit con1 om_c enpp1_c i.parl_cheib i.bicam i.fed i.EU logsalience_c year2_c if mip_v1!=. || issue: 
* Model 6
melogit con1 om_c enpp1_c i.parl_cheib i.bicam i.fed i.EU mip_v1_c year2_c if mip_v1!=. || issue:
* Model 7
melogit con1 om_c enpp1_c inflexec_c i.bicam i.fed i.EU logsalience_c year2_c if mip_v1!=. || issue: 
* Model 8
melogit con1 om_c enpp1_c inflexec_c i.bicam i.fed i.EU mip_v1_c year2_c if mip_v1!=. || issue: 


*** Figure G1
* (a)
meologit policy3n1 c.p1_c##c.enpp1_c c.p1_c##i.parl_cheib c.p1_c##i.bicam c.p1_c##i.fed c.p1_c##i.EU c.p1_c##c.logsalience_c c.p1_c##c.year2_c || issue: p1_c, cov(uns)
margins, dydx(p1_c) at(enpp1_c=(-2(1)5))
marginsplot, recast(line) recastci(rline) ciopts(lpattern(dash) lcolor(black)) scheme(s2mono) graphregion(color(white)) ylabel(-1.5(.5)1.5, nogrid) xlabel(-2(1)5)
* (b)
meologit policy3n1 c.p1_c##c.plur c.p1_c##i.parl_cheib c.p1_c##i.bicam c.p1_c##i.fed c.p1_c##i.EU c.p1_c##c.logsalience_c c.p1_c##c.year2_c || issue: p1_c, cov(uns)
margins, dydx(p1_c) at(plur=(0 1))
marginsplot, recast(dot) ciopts(lpattern(solid) lcolor(black)) scheme(s2mono) graphregion(color(white)) ylabel(-1(.5)1, nogrid)
* (c)
meologit policy3n1 c.p1_c##c.gallyear c.p1_c##i.parl_cheib c.p1_c##i.bicam c.p1_c##i.fed c.p1_c##i.EU c.p1_c##c.logsalience_c c.p1_c##c.year2_c || issue: p1_c, cov(uns)
margins, dydx(p1_c) at(gallyear=(0(2)22))
marginsplot, recast(line) recastci(rline) ciopts(lpattern(dash) lcolor(black)) scheme(s2mono) graphregion(color(white)) ylabel(-1(.5)1, nogrid) xlabel(0(5)22)
* (d)
meologit policy3n1 c.p1_c##c.distmagyear c.p1_c##i.parl_cheib c.p1_c##i.bicam c.p1_c##i.fed c.p1_c##i.EU c.p1_c##c.logsalience_c c.p1_c##c.year2_c || issue: p1_c, cov(uns)
margins, dydx(p1_c) at(distmagyear=(0(10)150))
marginsplot, recast(line) recastci(rline) ciopts(lpattern(dash) lcolor(black)) scheme(s2mono) graphregion(color(white)) ylabel(-1(.5)1, nogrid) xlabel(0(50)150)


*** Figure G2
* (a)
meologit policy3n1 c.p1_c##c.enpp1_c c.p1_c##i.parl_cheib c.p1_c##i.bicam c.p1_c##i.fed c.p1_c##i.EU c.p1_c##c.logsalience_c c.p1_c##c.year2_c || issue: p1_c, cov(uns)
margins, dydx(p1_c) at(parl_cheib=(0(1)2))
marginsplot, recast(dot) ciopts(lpattern(solid) lcolor(black)) scheme(s2mono) graphregion(color(white)) ylabel(-1(.5)1, nogrid) xlabel(0(1)2)
* (b)
meologit policy3n1 c.p1_c##c.enpp1_c c.p1_c##c.inflexec_c c.p1_c##i.bicam c.p1_c##i.fed c.p1_c##i.EU c.p1_c##c.logsalience_c c.p1_c##c.year2_c || issue: p1_c, cov(uns)
margins, dydx(p1_c) at(inflexec_c=(-5.8(.4)1.2))
marginsplot, recast(line) recastci(rline) ciopts(lpattern(dash) lcolor(black)) scheme(s2mono) graphregion(color(white)) ylabel(-1(.5)1, nogrid) xlabel(-6(2)2)


*** Figure G3
meologit policy3n1 c.p1_c##c.enpp1_c c.p1_c##i.parl_cheib c.p1_c##i.bicam c.p1_c##i.fed c.p1_c##i.EU c.p1_c##c.logsalience_c c.p1_c##c.year2_c || issue: p1_c, cov(uns)
* (a)
margins, dydx(p1_c) at(bicam=(0 1))
marginsplot, recast(dot) ciopts(lpattern(solid) lcolor(black)) scheme(s2mono) graphregion(color(white)) ylabel(-1(.5)1, nogrid) xlabel(0 1) 
* (b)
margins, dydx(p1_c) at(fed=(0(1)2))
marginsplot, recast(dot) ciopts(lpattern(solid) lcolor(black)) scheme(s2mono) graphregion(color(white)) ylabel(-1(.5)1, nogrid) xlabel(0(1)2) 
* (c)
margins, dydx(p1_c) at(EU=(0 1))
marginsplot, recast(dot) ciopts(lpattern(solid) lcolor(black)) scheme(s2mono) graphregion(color(white)) ylabel(-1(.5)1, nogrid) xlabel(0 1) 


*** Table H1
* Model 3
ologit policy3n1 p1_c c.p1_c#c.enpp1_c c.p1_c#i.parl_cheib c.p1_c#i.bicam c.p1_c#i.fed c.p1_c#i.EU c.p1_c##c.logsalience_c c.p1_c##c.year2_c i.country, robust
* Model 4
ologit policy3n1 p1_c c.p1_c#c.enpp1_c c.p1_c#c.inflexec_c c.p1_c#i.bicam c.p1_c#i.fed c.p1_c#i.EU c.p1_c##c.logsalience_c c.p1_c##c.year2_c i.country, robust


*** Table H2 
logit con1 om_c enpp1_c i.EU logsalience_c year2_c i.country, robust


*** Table J1
* ENPP
melogit con1 enpp1_c i.parl_cheib i.bicam i.fed i.EU logsalience_c year2_c || issue: 
melogit con1 enpp1_c inflexec_c i.bicam i.fed i.EU logsalience_c year2_c || issue: 
* PR/majoritarian system dummy
melogit con1 plur i.parl_cheib i.bicam i.fed i.EU logsalience_c year2_c || issue: 
* Gallagher Index
melogit con1 gallyear i.parl_cheib i.bicam i.fed i.EU logsalience_c year2_c || issue: 
* Average district magnitude
melogit con1 distmagyear i.parl_cheib i.bicam i.fed i.EU logsalience_c year2_c || issue:



	